﻿<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
    xmlns:md23="http://www.robot-electronics.co.uk/2006/10/md23hardware.html"
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />
  <xsl:output method="html"  version="4.01" encoding="utf-8" indent="yes"
              doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
              doctype-system="http://www.w3.org/TR/html4/loose.dtd" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      MD23 Hardware Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      MD23 Hardware Service
    </xsl:variable>
    <xsl:variable name="description">
      The MD23 is a robust I2C dual motor driver designed for use with EMG30 motors, and supports current sensing and 360 step encoders.
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />
        
        <style type="text/css"> 
          /* Service-specific stylesheet goes here */
        </style>

        <script language="javascript" type="text/javascript" src="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Javascript.js" />
          <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */
dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->


  <xsl:template match="/md23:MD23HardwareState">
        <!--span class="PageName">
          MD23 Hardware Service <img src="/resources/MD23Hardware/Devantech.Services.MD23.Hardware.resources.DevantechMD23Hardware.Image.png"/>
        </span-->
          <div class="Module">
          <div class="RightColumn">
            <xsl:for-each select="md23:Motors/*">
              <br/>
              <br/>
              <span class="SubTitle" >
                Motor
                <xsl:value-of select="position()-1"/>
              </span>
              <br/>
              <span class="key">
                Power (last set):
              </span>
              <span class="value">
                <xsl:value-of select="md23:Power"/>
              </span>
              <br/>
              <span class="key">
                Current:
              </span>
              <span class="value">
                <xsl:value-of select="md23:Current"/>
              </span>
              <br/>
              <span class="key">
                Encoder Ticks:
              </span>
              <span class="value">
                <xsl:value-of select="md23:EncoderTicks"/>
              </span>
            </xsl:for-each>
          </div>

          <span class="ModuleName">
            MD23 found at I2C Address <xsl:value-of select="md23:I2CAddress"/>
          </span>
          <br/>
          <span class="SmallText">
            Last contact: <xsl:value-of select="md23:Timestamp"/>
          </span>
          <br/>
          <br/>

          <span class="key">
            Battery Voltage:
          </span>
          <span class="value">
            <xsl:value-of select="md23:BatteryVoltage"/>
          </span>
          <br/>

          <span class="key">
            Mode:
          </span>
          <span class="value">
            <xsl:value-of select="md23:Mode"/>
          </span>
          <br/>

          <span class="key">
            Acceleration Rate:
          </span>
          <span class="value">
            <xsl:value-of select="md23:AccelerationRate"/>
          </span>
          <br/>
          <span class="key">
            Automatic Speed Control:
          </span>
          <span class="value">
            <xsl:value-of select="md23:AutomaticSpeed"/>
          </span>
          <br/>
          <span class="key">
            Automatic Motor Timeout:
          </span>
          <span class="value">
            <xsl:value-of select="md23:AutomaticMotorTimeout"/>
          </span>
          <br/>
        </div>

        <br clear="all" />

        <div class="hr"></div>

        <div class="RightColumn">
          <form method="POST" >
            <fieldset id="Enable" class="none">
              <legend>Enable</legend>
              <div class="helpText">Enables polling.</div>
              <label for="Enabled">Enabled</label>
              <div class="fieldRowRight">
                <select id="Enabled" name="Enabled" type="text" value="" class="Editable"
                  onfocus="op(this, 'Enable');"
                  title="Click to edit. Enables the service to poll for updates">
                  <xsl:choose>
                    <xsl:when test="md23:Enabled = 'true'">
                      <option value="True" selected="selected">True</option>
                      <option value="False">False</option>
                    </xsl:when>
                    <xsl:otherwise>
                      <option value="True">True</option>
                      <option value="False" selected="selected">False</option>
                    </xsl:otherwise>
                  </xsl:choose>
                </select>
              </div>
              <div class="submitButtons" id="EnableButtons">
                <input type="reset" value="Cancel"  onclick="of('Enable');" class="OrangeButton" /> or <input type="submit" value="Set" id="EnableSubmit" class="OrangeButton" />
              </div>
            </fieldset>
          </form>
        </div>

        <div class="RightColumn">
          <form method="POST" >
            <fieldset id="SetPollDelay" class="none">
              <legend>Poll Delay</legend>
              <div class="helpText">The time between polls.</div>
              <label for="Delay">Delay</label>
              <div class="fieldRowRight">
                <input id="Delay" name="Delay" type="text" class="Editable"
                  onfocus="op(this, 'SetPollDelay');"
                  title="Click to edit. The delay in miliseconds between polling.">
                  <xsl:attribute name="value">
                    <xsl:value-of select="md23:Delay"/>
                  </xsl:attribute>
                </input>
              </div>

              <div class="submitButtons" id="SetPollDelayButtons">
                <input type="reset" value="Cancel"  onclick="of('SetPollDelay');" class="OrangeButton" /> or <input type="submit" value="Set PollDelay" id="SetPollDelaySubmit" class="OrangeButton" />
              </div>
            </fieldset>
          </form>
        </div>

        <div class="RightColumn">
          <form method="POST" >
            <input type="hidden" name="Stop" value="true"/>
            <fieldset id="AllStop" class="selected">
              <legend>All Stop</legend>
              <div class="helpText">Stops both motors</div>
              <div class="submitButtonsSelected" id="AllStopButtons">
                <input type="submit" value="Stop" id="AllStopSubmit" class="OrangeButton" />
              </div>
            </fieldset>
          </form>
        </div>

        <div class="RightColumn">
          <form method="POST" >
            <input type="hidden" name="Reset" value="true"/>
            <fieldset id="ResetEncoders" class="selected">
              <legend>Reset Encoders</legend>
              <div class="helpText">Returns the encoder ticks to zero.</div>
              <div class="submitButtonsSelected" id="ResetEncodersButtons">
                <input type="submit" value="Reset" id="ResetEncodersSubmit" class="OrangeButton" />
              </div>
            </fieldset>
          </form>
        </div>

        <form method="POST" >
          <fieldset id="SetMotorPower" class="none">
            <legend>Motor Power</legend>
            <div class="helpText">Sets the power of a motor.</div>
            <label for="MotorID">Motor ID</label>
            <div class="fieldRowRight">
              <select id="MotorID" name="MotorID" type="text" value="" class="Editable"
                 onfocus="op(this, 'SetMotorPower');"
                 title="Click to edit. (byte) The ID of the motor.">
                <option value="0" selected="selected">Left (0)</option>
                <option value="1">Right (1)</option>
              </select>
            </div>
            <br/>
            <label for="Power">Power</label>
            <div class="fieldRowRight">
              <input id="Power" name="Power" type="text" class="Editable"
                onfocus="op(this, 'SetMotorPower');"
                title="Click to edit. (byte) The power to set.">
                <xsl:attribute name="value">
                  <xsl:value-of select="//md23:Motors/md23:Motor[position() = 1]/md23:Power"/>
                </xsl:attribute>
              </input>
            </div>
            <div class="submitButtons" id="SetMotorPowerButtons">
              <input type="reset" value="Cancel"  onclick="of('SetMotorPower');" class="OrangeButton" /> or <input type="submit" value="Set MotorPower" id="SetMotorPowerSubmit" class="OrangeButton" />
            </div>
          </fieldset>
        </form>
        <form method="POST" >
          <fieldset id="SetMotorPowers" class="none">
            <legend>Motor Powers</legend>
            <div class="helpText">Sets the power of each motor. (Requires Mode 0)</div>
            <label for="Power1">Left Power</label>
            <div class="fieldRowRight">
              <input id="Power1" name="Power1" type="text" class="Editable"
                onfocus="op(this, 'SetMotorPowers');"
                title="Click to edit. (byte) The power of motor 1.">
                <xsl:attribute name="value">
                  <xsl:value-of select="//md23:Motors/md23:Motor[position() = 1]/md23:Power"/>
                </xsl:attribute>
              </input>
            </div>

            <label for="Power2">Right Power</label>
            <div class="fieldRowRight">
              <input id="Power2" name="Power2" type="text" class="Editable"
                onfocus="op(this, 'SetMotorPowers');"
                title="Click to edit. (byte) The power of motor 2.">
                <xsl:attribute name="value">
                  <xsl:value-of select="//md23:Motors/md23:Motor[position() = 2]/md23:Power"/>
                </xsl:attribute>
              </input>
            </div>

            <div class="submitButtons" id="SetMotorPowersButtons">
              <input type="reset" value="Cancel"  onclick="of('SetMotorPowers');" class="OrangeButton" /> or <input type="submit" value="Set MotorPowers" id="SetMotorPowersSubmit" class="OrangeButton" />
            </div>
          </fieldset>
        </form>
        <form method="POST" >
          <fieldset id="SetSpeedAndTurn" class="none">
            <legend>Speed And Turn</legend>
            <div class="helpText">Turn-128 is added or subtracted to speed. (Requires Mode 2)</div>
            <label for="Speed">Speed</label>
            <div class="fieldRowRight">
              <input id="Speed" name="Speed" type="text" class="Editable"
                onfocus="op(this, 'SetSpeedAndTurn');"
                title="Click to edit. (byte)The speed (128 is stopped)">
                <xsl:attribute name="value">
                  <xsl:value-of select="//md23:Motors/md23:Motor[position() = 1]/md23:Power"/>
                </xsl:attribute>
              </input>
            </div>

            <label for="Turn">Turn</label>
            <div class="fieldRowRight">
              <input id="Turn" name="Turn" type="text" class="Editable"
                onfocus="op(this, 'SetSpeedAndTurn');"
                title="Click to edit. (byte)The turn (0 is no turn)">
                <xsl:attribute name="value">
                  <xsl:value-of select="//md23:Motors/md23:Motor[position() = 2]/md23:Power"/>
                </xsl:attribute>
              </input>
            </div>

            <div class="submitButtons" id="SetSpeedAndTurnButtons">
              <input type="reset" value="Cancel"  onclick="of('SetSpeedAndTurn');" class="OrangeButton" /> or <input type="submit" value="Set SpeedAndTurn" id="SetSpeedAndTurnSubmit" class="OrangeButton" />
            </div>
          </fieldset>
        </form>

        <form method="POST" >
          <fieldset id="SetAccelerationRate" class="none">
            <legend>Acceleration Rate</legend>
            <div class="helpText">The rate of acceleration.</div>
            <label for="AccelerationRate">Acceleration Rate</label>
            <div class="fieldRowRight">
              <input id="AccelerationRate" name="AccelerationRate" type="text" class="Editable"
                onfocus="op(this, 'SetAccelerationRate');"
                title="Click to edit. ">
                <xsl:attribute name="value">
                  <xsl:value-of select="md23:AccelerationRate"/>
                </xsl:attribute>
              </input>
            </div>

            <div class="submitButtons" id="SetAccelerationRateButtons">
              <input type="reset" value="Cancel"  onclick="of('SetAccelerationRate');" class="OrangeButton" /> or <input type="submit" value="Set AccelerationRate" id="SetAccelerationRateSubmit" class="OrangeButton" />
            </div>
          </fieldset>
        </form>

        <form method="POST" >
          <fieldset id="SetConfiguration" class="none">
            <legend>Configuration</legend>
            <div class="helpText">Core parameters of the MD23.</div>
            <label for="Mode">Mode</label>

            <div class="fieldRowRight">
              <select id="Mode" name="Mode" type="text" value="" class="Editable"
                onfocus="op(this, 'SetConfiguration');"
                title="Click to edit. (byte 0-3) The mode (Default, Signed, Turn, Signed Turn)">
                <option value="0">
                  <xsl:if test="md23:Mode = 0">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:text>Default (0)</xsl:text>
                </option>
                <option value="1">
                  <xsl:if test="md23:Mode = 1">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:text>Signed (1) - not used</xsl:text>
                </option>
                <option value="2">
                  <xsl:if test="md23:Mode = 2">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:text>Turn (2)</xsl:text>
                </option>
                <option value="3">
                  <xsl:if test="md23:Mode = 3">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:text>Signed Turn (3) - not used</xsl:text>
                </option>
              </select>
            </div>
            <br/>
            <label for="AutomaticSpeed">Automatic Speed</label>
            <div class="fieldRowRight">
              <select id="AutomaticSpeed" name="AutomaticSpeed" type="text" value="" class="Editable"
                onfocus="op(this, 'SetConfiguration');"
                title="Click to edit. Enables Automatic Speed Control.">
                <xsl:choose>
                  <xsl:when test="md23:AutomaticSpeed = 'true'">
                    <option value="True" selected="selected">True</option>
                    <option value="False">False</option>
                  </xsl:when>
                  <xsl:otherwise>
                    <option value="True">True</option>
                    <option value="False" selected="selected">False</option>
                  </xsl:otherwise>
                </xsl:choose>
              </select>
            </div>
            <br/>
            <label for="AutomaticMotorTimeout">Automatic Timeout</label>
            <div class="fieldRowRight">
              <select id="AutomaticMotorTimeout" name="AutomaticMotorTimeout" type="text" value="" class="Editable"
                onfocus="op(this, 'SetConfiguration');"
                title="Click to edit. Enables Automatic Motor Timeout.">
                <xsl:choose>
                  <xsl:when test="md23:AutomaticMotorTimeout = 'true'">
                    <option value="True" selected="selected">True</option>
                    <option value="False">False</option>
                  </xsl:when>
                  <xsl:otherwise>
                    <option value="True">True</option>
                    <option value="False" selected="selected">False</option>
                  </xsl:otherwise>
                </xsl:choose>
              </select>
            </div>
            <div class="submitButtons" id="SetConfigurationButtons">
              <input type="reset" value="Cancel"  onclick="of('SetConfiguration');" class="OrangeButton" /> or <input type="submit" value="Set Configuration" id="SetConfigurationSubmit" class="OrangeButton" />
            </div>
          </fieldset>
        </form>
        <br clear="left"/>

        <br clear="all"/>
        <div class="hr" />
        <div class="RightColumn">
          <a class="LinkSmall"
						href="http://www.robot-electronics.co.uk/htm/md23tech.htm"
						target="_new">View Devantech Documentation...</a>
        </div>
        Config at: /store/Devantech.Services.MD23.Hardware.xml
  </xsl:template>
</xsl:stylesheet>
